package mbms.mobilebudget;

import java.sql.SQLException;
import java.util.List;

import mbms.mobilebudget.database.DatabaseHandler;
import mbms.mobilebudget.entity.BankAccount;
import mbms.mobilebudget.entity.CreditCard;
import mbms.mobilebudget.entity.User;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.j256.ormlite.dao.Dao;

@SuppressLint("ShowToast")
public class UserManager {

	private DatabaseHandler helper;
	private Context context;
	private User authenticatedUser;

	public UserManager(DatabaseHandler helper, Context context, User authenticatedUser) {
		this.helper = helper;
		this.context = context;
		this.authenticatedUser = authenticatedUser;
	}
	
	public List<BankAccount> getBankAccountList(){
		try {
			if(authenticatedUser == null || authenticatedUser.getId()==null){
				Toast.makeText(context, "list failed", Toast.LENGTH_LONG);
				return null;
			}
			Dao<BankAccount,Integer> bankAccountDao = helper.getBankAccountDao();
			List <BankAccount> accounts = bankAccountDao.queryForEq("user_id", authenticatedUser.getId());
			return accounts;
			
		} catch (SQLException e) {
			Log.e("list", "failed");
		}
		
		return null;
	}
	
	public List<CreditCard> getCreditCardList(){
		try {
			if(authenticatedUser == null || authenticatedUser.getId()==null){
				Toast.makeText(context, "list failed", Toast.LENGTH_LONG);
				return null;
			}
			Dao<CreditCard,Integer> creditCardDao = helper.getCreditCardDao();
			List <CreditCard> accounts = creditCardDao.queryForEq("user_id", authenticatedUser.getId());
			
			return accounts;
		} catch (SQLException e) {
			Log.e("error", "list credit card");
		}
		
		return null;
	}
}

